Skip to content

Fix invalid enum output when x-enum-descriptions contains a line break#2838

Open
greymoth-jp wants to merge 1 commit into
openapi-ts:mainfrom
greymoth-jp:fix-enum-description-line-break
Open

Fix invalid enum output when x-enum-descriptions contains a line break#2838
greymoth-jp wants to merge 1 commit into
openapi-ts:mainfrom
greymoth-jp:fix-enum-description-line-break

Conversation

@greymoth-jp

Copy link
Copy Markdown

When the enum option is enabled, each member's // comment is taken from x-enum-descriptions / x-enumDescriptions. The description is handed to addSyntheticLeadingComment as single-line comment trivia, so a value that contains a line break ends the // comment at the first newline and the remaining text is printed as code. The generated enum then fails to parse.

For example, an x-enum-descriptions entry of "Code 100\nspanning two lines" currently produces:

enum ErrorCode {
    // Code 100
spanning two lines
    Value100 = 100,
}

addJSDocComment already handles this for property descriptions by running them through LB_RE (and escaping */), but tsEnumMember was the one comment path that skipped it. This change collapses internal line breaks in the enum-member description with the same LB_RE, so it stays on the single // line:

enum ErrorCode {
    // Code 100 spanning two lines
    Value100 = 100,
}

Single-line descriptions are unaffected.

Verification: added a tsEnum unit test in test/lib/ts.test.ts. It fails on main (the second line lands outside the comment) and passes with this change; the remaining ts.test.ts cases and the enum transform tests still pass.

@greymoth-jp greymoth-jp requested a review from a team as a code owner June 29, 2026 12:25
@greymoth-jp greymoth-jp requested a review from gzm0 June 29, 2026 12:25
@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 60f988a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Jun 29, 2026

Copy link
Copy Markdown

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 60f988a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant